<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

	public function index() {

		$this->load->view('admin/login.html');
	}

	public function captcha() {
		$config = array(
			'width' => 80,
			'height' => 20,
			'codeLen' => 1,
			'fontSize' => 16
			);
		$this->load->library('code', $config);
		$this->code->show();
	}

	public function login_in() {
		$captcha = $this->input->post('captcha');
		if (!isset($_SESSION)) {
			session_start();
		}
		if (strtoupper($captcha) != $_SESSION['code']) error('验证码错误');

		$this->load->model('admin_model', 'admin');

		$username = $this->input->post('username');
		$passwd = md5($this->input->post('passwd'));
		$user_data = $this->admin->check($username);


		if (!$user_data || $passwd != $user_data['password']) {
			error('用户名或密码不正确');
		}

		$array = array(
			'uid' => $user_data['uid'],
			'username'=> $user_data['username']
		);
		
		$this->session->set_userdata( $array );
		redirect('admin/admin');
	}

	public function login_out() {
		$this->session->sess_destroy();
		redirect('admin/login');
	}

}

/* End of file login.php */
/* Location: ./application/controllers/admin/login.php */